<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<spring:message code="button.search.text" var="searchText"/>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.configration.sev"/></h1>
	<small><spring:message code="menu.configration.sev.desc"/></small>
</div>
<form:form modelAttribute="pagingModel" role="form" cssClass="col-sm-12">
	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
	<input id="currentPage" name="currentPage" type="hidden" value="${pagingModel.currentPage}" />
	<div class="col-sm-12 form-group">
		<div class="col-sm-offset-7 col-sm-3">
			<div class="input-group">
				<input type="text" placeholder="${searchText }" name="searchAndCondition['variableName']" class="form-control" value="${pagingModel.searchAndCondition['variableName']}" />
				<span class="input-group-btn">
					<button class="btn btn-primary"><spring:message code="button.search"/></button>
				</span>
			</div>
		</div>
		<div class="col-sm-2">
		<form:select path="viewRow" cssClass="form-control">
			<form:option value="10">10 개</form:option>
			<form:option value="25">25 개</form:option>
			<form:option value="50">50 개</form:option>
			<form:option value="100">100 개</form:option>
		</form:select>
		</div>
	</div>
	<div class="form-group">
		<table class="table table-hover">
			<thead>
				<tr>
					<th><spring:message code="configration.sev.variableTitle"/></th>
					<th><spring:message code="common.writer"/></th>
					<th><spring:message code="common.updatedDate"/></th>
				</tr>
			</thead>
			<tbody>
				<c:choose>
					<c:when test="${empty pagingModel.lists }">
						<tr class="warning text-center">
							<td colspan="3"><spring:message code="list.no.result"/></td>
						</tr>
					</c:when>
					<c:otherwise>
						<c:forEach items="${pagingModel.lists }" var="item">
						<tr>
							<c:choose>
								<c:when test="${param['ip'] eq 'Y' }"><td><a href="#" class="btnVaraibleSelected" data-variableid="${item.variableid }" data-variableName="">${item.variableName }</a></td></c:when>
								<c:otherwise><td><a href="#" class="btn_link"  data-link="./view?variableid=${item.variableid }">${item.variableName }</a></td></c:otherwise>
							</c:choose>
							<td>${item.writer }</td>
							<td>${item.updatedDate }</td>
						</tr>
						</c:forEach>
					</c:otherwise>
				</c:choose>
			</tbody>
		</table>
	</div>
	<div class="form-group text-center">
		<c:choose>
			<c:when test="${param['ip'] eq 'Y' }">
				<c:if test="${not empty pagingModel.lists }">
				<ul class="pagination">
					<li><a href="#" class="pagesInPage" data-target="additionalContentZone" data-url="${CONTEXT }/configration/sev/lists" data-page="${pagingModel.paging.previousBlock }">&laquo;</a></li>
					<c:forEach items="${pagingModel.paging.pages }" var="pages">
					<c:choose>
						<c:when test="${pages eq pagingModel.paging.currentPageNum }">
							<li class="active"><a href="#" class="pagesInPage" data-target="additionalContentZone" data-url="${CONTEXT }/configration/sev/lists" data-page="${pages }">${pages }</a></li>
						</c:when>
						<c:otherwise>
							<li><a href="#" class="pagesInPage" data-target="additionalContentZone" data-url="${CONTEXT }/configration/sev/lists" data-page="${pages }">${pages }</a></li>
						</c:otherwise>
					</c:choose>
					</c:forEach>
					<li><a href="#" class="pagesInPage" data-target="additionalContentZone" data-url="${CONTEXT }/configration/sev/lists" data-page="${pagingModel.paging.nextBlock}">&raquo;</a></li>
				</ul>
				</c:if>
			</c:when>
			<c:otherwise>
				<c:if test="${not empty pagingModel.lists }">
				<ul class="pagination">
					<li><a href="#" class="pages" data-page="${pagingModel.paging.previousBlock }">&laquo;</a></li>
					<c:forEach items="${pagingModel.paging.pages }" var="pages">
					<c:choose>
						<c:when test="${pages eq pagingModel.paging.currentPageNum }">
							<li class="active"><a href="#" class="pages" data-page="${pages }">${pages }</a></li>
						</c:when>
						<c:otherwise>
							<li><a href="#" class="pages" data-page="${pages }">${pages }</a></li>
						</c:otherwise>
					</c:choose>
					</c:forEach>
					<li><a href="#" class="pages" data-page="${pagingModel.paging.nextBlock}">&raquo;</a></li>
				</ul>
				</c:if>
			</c:otherwise>
		</c:choose>
	</div>
	<c:choose>
		<c:when test="${param['ip'] eq 'Y' }">
			<input type="hidden" id="ip" name="ip" value="Y"/>
			<div class="form-group text-right">
				<button type="button" class="btn btn-default btnSubPageRevertMainView"><spring:message code="button.cancel"/></button>
				<c:if test="${not empty pagingModel.searchAndCondition['variableName']}">
				<button type="button" class="btn btn-default btnSubPageAddVariable"><spring:message code="button.list"/></button>
				</c:if>
			</div>
		</c:when>
		<c:otherwise>
			<div class="form-group text-right">
				<c:if test="${not empty pagingModel.searchAndCondition['variableName']}">
				<button type="button" class="btn btn-default btn_link" data-link="./lists"><spring:message code="button.list"/></button>
				</c:if>
				<c:if test="${fn:contains(buttons , Authorities.CREATE)}">
				<button type="button" class="btn btn-primary btn_link" data-link="./createForm"><spring:message code="button.create"/></button>
				</c:if>
			</div>
		</c:otherwise>
	</c:choose>
</form:form>
<c:choose>
<c:when test="${param['ip'] eq 'Y' }">
<script type="text/javascript">
$(document).ready(function() {
	$("#pagingModel").submit(function(event) {
		event.preventDefault();
		Loading.show();
		$.post("${CONTEXT }/configration/sev/lists", $("#pagingModel").serialize(), function(result) {
			$("#additionalContentZone").html(result);	
		}).always(function() {
			Loading.hide();
		});
	});
});
</script>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>